/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input,  Radio, Select,Upload,Button ,Icon,TreeSelect } from 'antd';
import {connect} from 'dva';
const TreeNode = TreeSelect.TreeNode;
const FormItem = Form.Item;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      fileList: [],
    };
  }
  componentDidMount() {
  }
  renderTreeNodes=(data)=>{
    return data.map((item) => {
      if (item.children) {
        return (
          <TreeNode value={item.id} title={item.name} key={item.id} >
            {this.renderTreeNodes(item.children)}
          </TreeNode>
        );
      }
      return  <TreeNode value={item.id}  title={item.name} key={item.id} />
    });
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 8},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    const data=this.props.data
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            label={'水表号'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('meter_number', {
              initialValue:  this.props.editRecord.meter_number,
              rules: [{required: true, message:""}],
            })(
              <Input  disabled />
            )}
          </FormItem>
          <FormItem
            label={'用水性质'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator(`price_nature_id`, {
              rules: [{required: true, message:""}],
              initialValue:  this.props.editRecord.price_nature&&this.props.editRecord.price_nature.id,

            })(
              <Select  disabled>
                {
                  this.props.price_nature.map((item,index)=>{
                    return <Option key={index} value={item.id}>{item.name}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
          <FormItem
            label={'计费状态'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator(`billing_status`, {
              initialValue:  this.props.editRecord.billing_status.toString(),

            })(
              <Select >
                {
                  [{key:'-1',value:'不计费'},{key:'1',value:'计费'}].map((item,index)=>{
                    return <Option key={index} value={item.key}>{item.value}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
          <FormItem
            label={'欠费关阀'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator(`arrears_status`, {
              initialValue:  this.props.editRecord.arrears_status.toString(),

            })(
              <Select  >
                {
                  [{key:'-1',value:'不启用'},{key:'1',value:'启用'}].map((item,index)=>{
                    return <Option key={index} value={item.key}>{item.value}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
          <FormItem
            label={'余额报警'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator(`balance_alarm_status`, {
              initialValue:  this.props.editRecord.balance_alarm_status.toString(),
            })(
              <Select >
                {
                  [{key:'-1',value:'不报警'},{key:'1',value:'报警'}].map((item,index)=>{
                    return <Option key={index} value={item.key}>{item.value}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
          <FormItem
            label={'报警金额'}
            {...formItemLayoutWithLabel}
          >
            {getFieldDecorator(`balance_alarm_amount`, {
              initialValue:  this.props.editRecord.balance_alarm_amount,
            })(
              <Input />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
              备注
            </span>
            )}
          >
            {getFieldDecorator('remark', {
              initialValue: this.props.editRecord ? this.props.editRecord.remark : '',
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
